package com.compuvest.web;

// <editor-fold defaultstate="collapsed" desc="import">
import java.io.Serializable;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
// </editor-fold>

public class Preference implements Serializable {

// <editor-fold defaultstate="collapsed" desc="init">
    private String title = "";
    private List<String> contents;
    private Map<String,Integer> countContent;
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Preference()">

    public Preference() {
        contents = new ArrayList<String>(70);
        countContent = new HashMap<String,Integer>(70);
    }
// </editor-fold>

    public int getCount(String name)    { return countContent.get(name); }

    public String getTitle()            { return title; }
    public void setTitle(String title)	{ this.title = title; }

// <editor-fold defaultstate="collapsed" desc="getContents()">

    public List<String> getContents() {

	if(contents.isEmpty()) return null;

        Collections.sort(contents, new AlphanumComparator());
        return contents;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="addContent()">

    public void addContent(String content) {

	if(content == null || content.length() == 0 || contents.contains(content)) return;
        contents.add(content);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="getBlock()">

    public List<String> getBlock() {

	if(contents.isEmpty()) return null;

        Collections.sort(contents, new AlphanumComparator());
        return contents;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="addContentCount()">

    public void addContentCount(String word) {

        if(word == null || word.length() == 0) return;

        if(countContent.containsKey(word)) {
            countContent.put(word, countContent.get(word).intValue() + 1);
        }
        else {
            countContent.put(word, 1);

            contents.add(word);
        }
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="toString()">

    @Override
    public String toString() {
        return title;
    }
// </editor-fold>

}
